package indi.zhang.ttl.config;

import com.alibaba.ttl.threadpool.TtlExecutors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TTLConfig {

    @Value("${async.ttl.core_pool_size:8}")
    private int corePoolSize;
    @Value("${async.ttl.max_pool_size:16}")
    private int maxPoolSize;

    @Bean("executorService")
    public ExecutorService newCachedThreadPool() {

         return TtlExecutors.getTtlExecutorService(new ThreadPoolExecutor(corePoolSize, maxPoolSize,
                 60L, TimeUnit.SECONDS,
                 new SynchronousQueue<Runnable>()));
    }

}
